package myaction.admin.courseinfo;

import myutil.DbUtil;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

public class AdminCoursesPreAddAction extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doPost(request, response);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String sql = "select * from t_teachers";
        request.setCharacterEncoding("utf-8");
        List lstv = new ArrayList();
        try {
            Connection cn = DbUtil.getConn();
            Statement sm = cn.createStatement();
            ResultSet rs = sm.executeQuery(sql);
            while (rs.next()) {
                List lstt = new ArrayList();
                lstt.add(rs.getInt("t_id"));
                lstt.add(rs.getString("t_name"));
                lstv.add(lstt);
            }
            System.out.println("数据发送完毕！");
            rs.close();
            sm.close();
            cn.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        request.setAttribute("lstv", lstv);
        request.getRequestDispatcher("admin/courseadd.jsp").forward(request,
                response);
    }
}
